using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Collections;

namespace DIEMRENLUYENSV.Class
{
    class C_CHUCVU
    {
        private Ketnoi kn;

        public Ketnoi Kn
        {
            get { return kn; }
            set { kn = value; }
        }
        private string databasename;

        public string Databasename
        {
            get { return databasename; }
            set { databasename = value; }
        }
        public C_CHUCVU()
        {
            Kn = new Ketnoi();
            databasename = "";
        }
        public C_CHUCVU(string servername, string user, string pass, string dbname)
        {
            Kn = new Ketnoi(servername, user, pass);
            databasename = dbname;
        }
        public DataTable Sellect()
        {
            Database db = Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from CHUCVU").Tables[0];
        }
        public void Update(E_CHUCVU x)
        {
            Database db= Kn._Server.Databases[databasename];
            db.ExecuteNonQuery("update CHUCVU set TENCV='"+x.Tencv+"',MUCDIEM ='"+int.Parse(x.Mucdiem.ToString())+"' where MACV= '"+int.Parse(x.Macv.ToString())+"'");
        }
        public void insert(E_CHUCVU x)
        {
          
            Database db = Kn._Server.Databases[databasename];
            db.ExecuteNonQuery("insert into CHUCVU(MACV,TENCV,MUCDIEM) values ('" + int.Parse(x.Macv.ToString()) + "','" + x.Tencv.ToString() + "','" + int.Parse(x.Mucdiem.ToString()) + "')");
        }
        public ArrayList SellectArr()
        {
            Database db = Kn._Server.Databases[databasename];
            DataTable dt = db.ExecuteWithResults("select MACV, TENCV,MUCDIEM from CHUCVU").Tables[0];
            ArrayList ar = new ArrayList();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Item t = new Item(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString());
                ar.Add(t);
            }
            return ar;
        }
    }
}
